package com.yuyuan.notice.controller;

import cn.hutool.core.bean.BeanUtil;
import com.yuyuan.api.domain.EventDTOC;
import com.yuyuan.api.domain.NoticeDTOC;
import com.yuyuan.common.domain.Result;
import com.yuyuan.notice.domain.po.Notice;
import com.yuyuan.notice.event.EventNoticeProducer;
import com.yuyuan.notice.mapper.NoticeMapper;
import com.yuyuan.notice.service.INoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yuyuan.notice.domain.Event;
/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/6/21
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    private INoticeService noticeService;

    @Autowired
    private NoticeMapper noticeMapper;

    @Autowired
    private EventNoticeProducer eventNoticeProducer;

    //获取通知(分页)
    @GetMapping("/get/{startId}")
    public Result getPageComment(@PathVariable Long startId){
        return noticeService.getPageNotices(startId);
    }

    // Client
    @PostMapping("/client/insert")
    public void insert(@RequestBody NoticeDTOC noticeDTOC){
        noticeMapper.insert(BeanUtil.copyProperties(noticeDTOC, Notice.class));
    }

    @PostMapping("/client/fireEvent")
    public void fireEvent(@RequestBody EventDTOC eventDTOC){
        eventNoticeProducer.fireEvent(BeanUtil.copyProperties(eventDTOC, Event.class));
    }
}
